package main;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;

import constants.Strings;

public class ServerThreadStarter extends Thread {
	Socket socket;
	int port; // for logging
	
	public ServerThreadStarter(Socket socket, int port) {
	    super("Server Thread");
	    this.socket = socket;
	    this.port = port;
	}
	
	public void run() {
		Server.log("Server:" + port + " - Accepted connection : " + socket);
		Server.log("Server" + port + " - Starting connection thread ...");
	    startThread();
	}
	
	private void startThread() {
	    try {
	    	DataInputStream dis = new DataInputStream(socket.getInputStream());
	    	DataOutputStream dos = new DataOutputStream(socket.getOutputStream()); 
	    	
            String input = "";
            try{
            	input = (String) dis.readUTF();
            }catch (Exception e){
            	Server.log(e.getMessage());
            }
            		
            ServerActions.performAction(input, dos, socket);
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}
}